<template>
	<!-- 考试详情-->
	<view class="body">
		<view>
			<Answer :isReviewed='true' currentSwiperItem='0' :duration='300' :questtionList='questtionList'
				@submit='handleSubmit' @onChange='onChange'></Answer>
		</view>
	</view>
</template>

<script>
	import myHeader from '../components/head.vue'
	import NetWorkTool from '@/api/netWorkTool'
	import Answer from './../components/dyw-answer/answer.vue'
	export default {
		data() {
			return {
				title: '考试中',
				userInfo: {}, //用户信息
				questtionList: [],
				loadingMessage: '',
				confirmSubmitContent: '',
				errMessage: '',
				weeklyId:""
			}

		},
		onLoad: function(option) {
			this.weeklyId = option.id;
		},
		created() {
				this.init();
		},
		methods: {
			// 初始化题目
			init() {
				NetWorkTool.POSTFORM('/api/weekly-question/queryExamInfo', {
					weeklyId: this.weeklyId
				}, true).then(res => {
					console.log(res)
					let arr = [];
					for (let item of res.question) {
						let o = {};
						o.id = item.id
						o.title = item.subject
						o.answer = item.answer
						o.score = item.score
						o.type = this.testEnum(item.type)
						let explainContent = item.userAnswer == undefined ? "" : item.userAnswer
						o.explainContent = "您的答案：" + explainContent
						o.userAnswer = item.userAnswer
						o.difficulty = ""
						// 解析选项
						let opts = [];
						let paserObj = JSON.parse(item.options)
						let mp = new Map(Object.entries(paserObj));
						mp.forEach((value, key, mp) => {
							opts.push({
								optionId: key,
								id: key,
								content: value,
								type: this.testEnum(item.type),
								questionId: item.id
							})
						})
						o.optionList = opts
						arr.push(o)
					}
					this.questtionList = arr
				})
			},
			handleSubmit(questtionList) {
				uni.redirectTo({
					url: './index',
				})
			},
			testEnum(desc) {
				if (desc == '单选题') {
					return 2;
				}
				if (desc == '多选题') {
					return 3;
				}
			}
		},
		components: {
			Answer
		},
	}
</script>

<style lang="scss">
	@import url("/static/party_building/assets/style/federation.css");

	page {
		background-color: #FFFFFF;
	}
</style>
